package com.controller;

import com.pojo.Btn;
import com.pojo.Menus;
import com.pojo.User;
import com.service.MenusService;
import com.service.impl.MenusServiceImpl;
import com.sun.org.apache.regexp.internal.RE;
import com.uilt.*;
import com.vo.DtreeVo;
import com.vo.TreeTableDto;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/menus")
public class MenusController extends BaseController {
    MenusService menusService  = new MenusServiceImpl();

    //查询所有菜单
    public LayuiTable<TreeTableDto> getMenus(HttpServletRequest request, HttpServletResponse response){
        LayuiTable<TreeTableDto> layuiTable=menusService.getMenusAll();
        return layuiTable;
    }

    public LayuiTable<DtreeVo> MenuAll(HttpServletRequest request, HttpServletResponse response){
        LayuiTable<DtreeVo> dtoLayuiTable=null;
        return dtoLayuiTable;
    }

   /* public String getMenus(HttpServletRequest request, HttpServletResponse resp){
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        List<Menus> menusAll = menusService.getMenusAll(user.getId(), 1);
        session.setAttribute("menusAll",menusAll);
        session.removeAttribute("userAll");
        session.removeAttribute("menusBtn");
        return "index1";
    }*/
    public InitMenus getMenusAll(HttpServletRequest request, HttpServletResponse resp){
        InitMenus initMenus = new InitMenus();
        IndexInfo homeInfo =new IndexInfo("首页","page/welcome-1.html?t=1");
        initMenus.setHomeInfo(homeInfo);
        IndexInfo lgonInfo =new IndexInfo("点餐系统管理","images/logo.png","");
        initMenus.setLogoInfo(lgonInfo);

        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        List<IndexInfo> menuInfo = menusService.getLayMenusAll(user.getId(),1);


        IndexInfo indexInfo  = new IndexInfo("常规管理","fa fa-address-book","_self","",menuInfo);


        List<IndexInfo> infoList = new ArrayList<>();
        infoList.add(indexInfo);




        initMenus.setMenuInfo(infoList);

        return initMenus;
    }


    //查询所有
    public String getBtn(HttpServletRequest request, HttpServletResponse response){
        response.setCharacterEncoding("utf-8");
        //查询按钮
        String pid1 = request.getParameter("pid");
        int pid = Integer.parseInt(pid1);
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        List<Menus> menusBtn = menusService.getMenusBtn(user.getId(), pid,2);
        session.setAttribute("menBtn",menusBtn);
        return "/admin/page/system/menu/menuList";
    }

    public ResPoneEntity getBtnAll(HttpServletRequest request, HttpServletResponse response){
        response.setCharacterEncoding("utf-8");
        //查询按钮
        List<Btn> menusBtn = menusService.getBtn();
        ResPoneEntity resPoneEntity = new ResPoneEntity();
        resPoneEntity.setState(200);
        resPoneEntity.setMsg("");
        resPoneEntity.setObject(menusBtn);
        return resPoneEntity;
    }





    @Override
    public Class getServletClass() {
        return MenusController.class;
    }
}
